//
//  XLVisitorTableViewController.swift
//  微博
//
//  Created by macbook on 16/9/29.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit

class XLVisitorTableViewController: UITableViewController {

    //标识用户没有登录
    let isLogin:Bool = XLUserAccountTools.shardTools.isLogin
    
    //需要时才创建
    var vistorView = XLVistorView?()
    
    override func loadView(){
        
        //代表用户登录了
        if isLogin {
            super.loadView()
        }else//没有登录,访问访客视图
        {
            setVistorView()
            
        }
    }
    
    //创建访客视图
    private func setVistorView()
    {
        setVistorLeftAddRightBarBtnItem()
        //创建自定义的并替换
        vistorView = XLVistorView()
        
        view = vistorView
        
        //调用相同方法
        vistorView?.close = {[weak self] in
        
            self?.loginBtnClick()
        
        }
    }
    
    
    //设置访客视图的两个按钮
    private func setVistorLeftAddRightBarBtnItem(){
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(XLVisitorTableViewController.loginBtnClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(XLVisitorTableViewController.loginBtnClick))
    }
    
    //登录和注册按钮的实现
    @objc private func loginBtnClick()
    {
        let vc = XLQauthViewController()
        let navc = UINavigationController(rootViewController: vc)
        
        presentViewController(navc, animated: true, completion: nil)
        
    }
    

    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

            }
    
}











